<script setup>
import { ElCard, ElButton, ElRow, ElCol } from "element-plus";

const props = defineProps({
	patientList: {
		type: Array,
		default: () => []
	},
	loading: {
		type: Boolean,
		default: false
	}
});

const emit = defineEmits(["selectExam", "viewReport"]);

// 选择检查记录
function handleSelectExam(exam) {
	console.log("=== ExamTable 按钮点击事件触发 ===");
	console.log("选择检查记录:", exam);
	console.log("studyInstanceUID:", exam.studyInstanceUID);
	console.log("studyInstanceUid:", exam.studyInstanceUid);
	console.log("检查是否禁用:", !(exam.studyInstanceUID || exam.studyInstanceUid));
	console.log("=== ExamTable 按钮点击事件结束 ===");

	emit("selectExam", exam);
}

// 查看报告
function handleViewReport(exam) {
	console.log("=== ExamTable 报告按钮点击事件触发 ===");
	console.log("查看报告:", exam);
	console.log("报告信息:", {
		patientName: exam.patientName,
		examDateTime: exam.examDateTime,
		examClass: exam.examClass,
		reportDoctor: exam.reportDoctor
	});
	console.log("=== ExamTable 报告按钮点击事件结束 ===");

	emit("viewReport", exam);
}
</script>

<template>
	<div class="exam-cards-container" v-if="patientList.length > 0">
		<div class="exam-cards" v-loading="loading">
			<el-card
				v-for="(exam, index) in patientList"
				:key="index"
				class="exam-card"
				shadow="hover"
			>
				<div class="exam-card-content">
					<div class="exam-info">
						<div class="info-row">
							<div class="info-item">
								<span class="label">检查时间：</span>
								<span class="value">{{ exam.examDateTime }}</span>
							</div>
							<div class="info-item">
								<span class="label">检查类别：</span>
								<span class="value">{{ exam.examClass }}</span>
							</div>
						</div>
						<div class="info-row">
							<div class="info-item">
								<span class="label">检查科室：</span>
								<span class="value">{{ exam.requestDeptName }}</span>
							</div>
							<div class="info-item">
								<span class="label">报告医生：</span>
								<span class="value">{{ exam.reportDoctor }}</span>
							</div>
						</div>
						<div class="info-row">
							<div class="info-item">
								<span class="label">审核医生：</span>
								<span class="value">{{ exam.requestDoctorName }}</span>
							</div>
						</div>
					</div>
					<div class="exam-actions">
						<el-button
							plain
							size="small"
							class="action-btn"
							@click="handleViewReport(exam)"
							>报告</el-button
						>
						<el-button
							plain
							size="small"
							class="action-btn"
							@click="handleSelectExam(exam)"
							:disabled="!(exam.studyInstanceUID || exam.studyInstanceUid)"
							>影像</el-button
						>
					</div>
				</div>
			</el-card>
		</div>
	</div>
</template>

<style scoped>
.exam-cards-container {
	margin-bottom: 20px;
	flex: 1;
	min-height: 200px;
	overflow: hidden;
}

.exam-cards {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
	gap: 16px;
	width: 100%;
}

.exam-card {
	border-radius: 12px;
	border: 1px solid #e4e7ed;
	transition: all 0.3s ease;
}

.exam-card:hover {
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
	transform: translateY(-2px);
}

.exam-card-content {
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.exam-info {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.info-row {
	display: flex;
	gap: 12px;
}

.info-item {
	display: flex;
	flex: 1;
	align-items: center;
	gap: 6px;
}

.label {
	font-weight: 500;
	color: #606266;
	font-size: 13px;
	white-space: nowrap;
	text-align: right;
	min-width: 60px;
	flex-shrink: 0;
}

.value {
	color: #303133;
	font-size: 13px;
	font-weight: 600;
	flex: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	text-align: left;
}

.exam-actions {
	display: flex;
	justify-content: flex-end;
	gap: 6px;
	padding-top: 6px;
	border-top: 1px solid #f0f0f0;
}

.action-btn {
	padding: 6px 12px;
	font-size: 12px;
	min-width: 50px;
	font-weight: 500;
	transition: all 0.2s ease;
}

.action-btn:first-child {
	background-color: #409eff;
	border-color: #409eff;
	color: white;
}

.action-btn:first-child:hover {
	background-color: #66b1ff;
	border-color: #66b1ff;
}

.action-btn:last-child {
	background-color: #67c23a;
	border-color: #67c23a;
	color: white;
}

.action-btn:last-child:hover {
	background-color: #85ce61;
	border-color: #85ce61;
}

.action-btn:last-child:disabled {
	background-color: #c0c4cc;
	border-color: #c0c4cc;
	color: #909399;
	cursor: not-allowed;
}

/* 移动端适配 */
@media (max-width: 768px) {
	.exam-cards {
		grid-template-columns: 1fr;
		gap: 12px;
	}

	.exam-card-content {
		padding: 10px;
		gap: 8px;
	}

	.info-row {
		flex-direction: column;
		gap: 6px;
	}

	.info-item {
		flex-direction: row;
		gap: 6px;
	}

	.label,
	.value {
		font-size: 12px;
	}

	.exam-actions {
		padding-top: 4px;
		gap: 4px;
	}

	.action-btn {
		padding: 4px 8px;
		font-size: 11px;
		min-width: 45px;
	}
}

/* 超小屏幕手机 (320px - 480px) */
@media (max-width: 480px) {
	.exam-cards {
		gap: 10px;
	}

	.exam-card-content {
		padding: 8px;
		gap: 6px;
	}

	.label,
	.value {
		font-size: 11px;
	}

	.action-btn {
		padding: 3px 6px;
		font-size: 10px;
		min-width: 40px;
	}
}

/* 平板设备适配 (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
	.exam-cards {
		grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
		gap: 14px;
	}

	.exam-card-content {
		padding: 14px;
	}

	.label,
	.value {
		font-size: 13px;
	}

	.action-btn {
		padding: 6px 12px;
		font-size: 12px;
		min-width: 50px;
	}
}

/* 大屏幕适配 */
@media (min-width: 1200px) {
	.exam-cards {
		grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
		gap: 18px;
	}
}
</style>
